package com.yanqu.road.server.logic.activity.condition.pasture.channel;

import com.yanqu.road.entity.activity.ActivityConditionInfo;
import com.yanqu.road.entity.activity.ActivityInfo;
import com.yanqu.road.entity.activity.args.ValueFourParamArgs;
import com.yanqu.road.entity.enums.eGamePlayerEventType;
import com.yanqu.road.pb.cross3.activity.EnterNameProto;
import com.yanqu.road.server.gameplayer.GamePlayer;
import com.yanqu.road.server.gameplayer.module.task.TaskModule;
import com.yanqu.road.server.logic.activity.BaseActivityData;
import com.yanqu.road.server.logic.activity.condition.BaseNewRankActivityCondition;
import com.yanqu.road.server.manger.activity.entername.EnterNameActivityMgr;
import com.yanqu.road.server.protocol.ChannelProtocol;

import java.math.BigInteger;

public class EnterNameAreaFightRankCondition extends BaseNewRankActivityCondition {

    public EnterNameAreaFightRankCondition(ActivityInfo activityInfo, ActivityConditionInfo activityConditionInfo, BaseActivityData baseActivityData) {
        super(activityInfo, activityConditionInfo, baseActivityData);
    }

    @Override
    protected void player_BoardLevelHandle(Object object) {
        ValueFourParamArgs args = (ValueFourParamArgs) object;
        if(args.getParams1() != baseActivityData.getActivityId()){
            return;
        }
        setValue(getValue().add(args.getValue()));

        //上报玩家勋章
        EnterNameProto.ChannelEnterNameChannelUserValueReqMsg.Builder upload = EnterNameProto.ChannelEnterNameChannelUserValueReqMsg.newBuilder();
        upload.setUserKey(EnterNameActivityMgr.buildKeyMsg(player.getUserId()));
        upload.setActivityId(baseActivityData.getActivityId());
        upload.setType(getConditionType());
        upload.setValue(getValue().toString());
        upload.setParam("");
        player.sendChannelPacket(ChannelProtocol.N_ENTER_NAME_CHANNEL_USER_VALUE, upload);
    }

    @Override
    public void addTrigger(GamePlayer player) {
        player.getModule(TaskModule.class).getGameEvent().addListener(eGamePlayerEventType.EnterNameAreaFightRank.getValue(), handle);
    }

    @Override
    public void removeTrigger(GamePlayer player) {
        player.getModule(TaskModule.class).getGameEvent().removeListener(eGamePlayerEventType.EnterNameAreaFightRank.getValue(), handle);
    }
}
